package com.test.demo.consumer;

import com.test.demo.provider.service.DemoService;
import org.apache.dubbo.config.annotation.Reference;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * 负载均衡
 */
@SpringBootTest
class LoadBalanceCosumer {

    //@Reference(version = "default",loadbalance = "roundrobin")    轮询
    //@Reference(version = "default",loadbalance = "random")    随机
    //@Reference(version = "default",loadbalance = "consistenthash")   一致性Hash -》 同样的Key调用的是同样的服务
    @Reference(version = "default",loadbalance = "leastactive")   //最少活跃调用数      如果耗时长则调用的比较少，耗时短则调用更多
    private DemoService demoService;
    @Test
    void contextLoads() {
        for (int i = 0; i < 50; i++) {
            System.out.println(demoService.sayHello("world"+i%3));
        }
    }

}
